<?php

/*

  Treasure	$3

  Worth $1
  When you play this, reveal cards from your deck until you reveal a Treasure. Discard it or trash it. Discard the other cards.

 */

class Loan extends Card implements iTreasure, iKingdom, iProsperity {

    public function __construct() {
        parent::__construct("Loan", 3);
        $this->value = new Price(1);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Worth $1",
            "When you play this, reveal cards from your deck until you reveal a Treasure. Discard it or trash it. Discard the other cards.");
    }
    
    public function autoPlayNum(Game $game) {
        return -1;
    }
    
    public function play(Game $game, $isRealCard) {
        $i = 0;
        $discardCards = array();
        $treasure_card = null;

        while ($i < 1) {
            $card = $game->peekCardFromDrawDeck();
            if (!$card)
                break;
            if ($card instanceof iTreasure) {
                $treasure_card = $card;
                $i+=1;
            } else {
                $card = $game->removeCardFromDrawDeck();
                $discardCards[] = $card;
            }
        }

        if ($treasure_card) {
             ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($treasure_card) . " and discard " . nicePrint($discardCards), "reveals " . nicePrint($treasure_card) . " and discards " . nicePrint($discardCards));
        }
        else {
             ScreenDisplay::addScreenMessage($game, true, "reveal no treasures and discard " . nicePrint($discardCards), "reveals no treasures and discards " . ScreenDisplay::$LMSG);
        }
        $game->discardTempDiscardCards($discardCards);

        if ($treasure_card) {
            
            $options = array(new Option(1, "Discard"), new Option(2, "Trash"));
            $output = MySocket::GetUserReply($game,  Input_ChooseOne, $options, 1, 1,  null,"Trash or discard " . $treasure_card->getValue());
            $answer = $output[0];
            if ($answer == "Discard") {
                $game->putCardInDiscardDeck($treasure_card);
                 ScreenDisplay::addScreenMessage($game, true, "discard ".  nicePrint($treasure_card), "discards ".ScreenDisplay::$LMSG);
            } else if ($answer == "Trash") {
                $game->putCardInTrash($treasure_card);
                 ScreenDisplay::addScreenMessage($game, true, "trash ".  nicePrint($treasure_card), "trashes ".ScreenDisplay::$LMSG);
            }
        }

        $game->cardPaymentFinished();

        return true;
    }
}

?>